package com.gis.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gis.bean.Lost;
import com.gis.dao.LostDao;
import com.gis.util.Constant;
import com.gis.util.ResponseUtil;
import com.gis.util.RestResponse;

@WebServlet("/lost/add")
public class LostAddServlet extends HttpServlet {
	LostDao lostDao = LostDao.getInstance();

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}



	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String username = req.getParameter("username");
		Integer goodsType = Integer.parseInt(req.getParameter("goodsType"));
		String lostTime = req.getParameter("lossTime");
		Double lng = Double.parseDouble(req.getParameter("lng"));
		Double lat = Double.parseDouble(req.getParameter("lat"));
		String address = req.getParameter("address");
		String description = req.getParameter("description");
		String fileName = req.getParameter("fileName");
		Lost lost = new Lost();
		lost.setUsername(username);
		lost.setGoodsTypeId(goodsType);
		lost.setLostTime(lostTime);
		lost.setLng(lng);
		lost.setLat(lat);
		lost.setAddress(address);
		lost.setDescription(description);
		lost.setFileName(fileName);
		int i = lostDao.add(lost);
		if (i > 0) {
			ResponseUtil.writeJson(resp, RestResponse.success(Constant.CREATE_SUCCESS));
		} else {
			ResponseUtil.writeJson(resp, RestResponse.fail(Constant.CREATE_FAILED));
		}
		
	}
	
	
}
